package qf.controller;


import qf.dao.UserDao;
import qf.dao.daoImpl.UserDaoImpl;
import qf.pojo.User;
import qf.service.AdminService;
import qf.service.serviceImpl.AdminServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.controller
 * @Description:
 * @Date 2022/5/20 14:36
 */
@WebServlet("/admin")
public class AdminController extends BaseServlet{
    public String login(HttpServletRequest request, HttpServletResponse response){
        UserDao userDao = new UserDaoImpl();
        AdminService adminService = new AdminServiceImpl(userDao);

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        User user = adminService.findAdmin(username, password);
        if (user == null) {
            return  "redirect:" + request.getContextPath() + "/admin/login.jsp";
        }
        if (user != null || "".equals(user)) {
            request.getSession().setAttribute("admin",user);
            return "redirect:" + request.getContextPath() + "/admin/admin.jsp";
        }else{
            return  "redirect:" + request.getContextPath() + "/admin/login.jsp";
        }
    }






}
